﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_CompetePriceSwitch : System.Web.UI.Page
{
    String ComSwitchPrj;
     int numbre = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
           
                 ComSwitchPrj = SysFun.IsSQL(Request.QueryString["projectid"]);
                
                string strsele = "select isnull(max(CompetitionNum),1) as CompetitionNum  from project_bid where projectid=" + ComSwitchPrj;
                Db db = new Db();
                DataTable dt = db.DataTable(strsele);
                db.Close();
                numbre = Convert.ToInt32(dt.Rows[0].ItemArray[0].ToString());
                 if ((numbre == 1) || (numbre == 0))
                { Label2.Text = "第一次竞价"; }
                //else if (numbre == 2)
                //{ Label2.Text = "第二次竞价"; }
                else
                { Label2.Text = "竞价结束"; }
                dt.Dispose();

               if (numbre > 1) { 
                   Response.Write("<script>alert('竞价结束！');</script>");
                   Submit5.Disabled = true;
                   Submit6.Disabled = true;
               }
             

                showdata();
            
        }
    }
/// <summary>
/// 数据绑定datagrid
/// </summary>
    protected void showdata()
    {
        Db db = new Db();
        DbPage dbPage = new DbPage(db);


     
        dbPage.Table = " CompeteTablevs ";                                               //表名，可以多个表关联
        dbPage.SelectFieldGroup = "AccountID,CompetitionSwich,CompanyName_TB,Usercode_TB";
        dbPage.Key = "Accountid";
        string sql = "";
        if (ComPanyName.Text.Trim().Length > 0)
        {
            sql = "(CompanyName_TB Like '%" + ComPanyName.Text.Trim() + "%' or Usercode_TB Like '%" + ComPanyName.Text.Trim() + "%') and ";
        }
        dbPage.Where = sql + " projectid=" + ComSwitchPrj + " and CompeteNum=" + numbre;// 在网下评分系统中将 未中标的 CompeteNum 置为 2 本次中标的不改，那么下次显示的就是竞价2的公司了

        dbPage.SelectField = "AccountID,CompetitionSwich,CompanyName_TB,Usercode_TB";                        //可以不设，默认为“*”

        dbPage.OrderBy = " CompanyName_TB,Accountid";                                //排序字段，可以不输入。不输入时以 Key 作为排序字段

        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]); //设置需要查询第几页
        dbPage.PageSize = 30;                                                   //设置每页显示多少条记录


        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("<table border=1 cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='98%'>");
        sb.Append("<tr>");
        sb.Append("<td class='table_title' nowrap>投标人</td>");
        sb.Append("<td class='table_title' nowrap>投标人注册号</td>");
        sb.Append("<td  class='table_title' nowrap>竞价状态</td>");
        sb.Append("</tr>");

        int intNum = 0, i, j = 0;
        string zhuangtai = "";//zhuangtai 表示审核状态

        System.Data.IDataReader dr = dbPage.ExecuteReaderGroup(60);
        while (dr.Read())
        {
            intNum++;
            i = SysFun.ToInt(dr["CompetitionSwich"]);
            if (i == 0)
            {
                zhuangtai = "关";
            }
            if (i == 1)
            {
                zhuangtai = "开";
            }
            if (j == 0)
            {
                sb.Append("<tr class='table_td'>");
                j++;
            }
            else
            {
                sb.Append("<tr class='table_td2'>");
                j--;
            }
            
            sb.Append("<td align='center'>" + SysFun.ToTrim(dr["CompanyName_TB"]) + "</td>");
            sb.Append("<td align='center'>" + SysFun.ToTrim(dr["Usercode_TB"]) + "</td>");
            sb.Append("<td align='center'>" + zhuangtai + "</td>");
            sb.Append("</tr>");
        }
        dr.Close();
        sb.Append("</table>");
        this.DbPageFlip1.DbPage = dbPage;
        Label1.Text = sb.ToString();
        db.Close();
       
    }
   
    protected void Submit5_ServerClick(object sender, EventArgs e) //开启
    {
        Db db = new Db();
        string strSql = "Update Project_Bid Set CompetitionSwich=1 Where Checkstatus=1 and Status=1 and Projectid='" + ComSwitchPrj + "'";
        db.Command(strSql);
        Response.Write("<script>window.alert('竞价报价全部开启！');</script>");
        db.Close();
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "Project_Bid", strSql, "../Agency/CompetePriceSwitch.aspx");
        Response.Write("<script>window.location=\"CompetePriceSwitch.aspx?Projectid=" + ComSwitchPrj.ToString() + "\"</script>");
        
    }
    protected void Submit6_ServerClick(object sender, EventArgs e) //关闭  ; 在网下评分系统中将 未中标的 CompeteNum 置为 2 本次中标的不改，那么下次显示的就是竞价2的公司了
    {
    
        Db db = new Db();
        string strSql = "Update Project_Bid Set CompetitionSwich=0,CompetitionNum=2  Where Checkstatus=1 and Status=1 and Projectid='" + ComSwitchPrj + "'";
        db.Command(strSql);
        Response.Write("<script>window.alert('竞价报价全部关闭！');</script>");
        db.Close();
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "Project_Bid", strSql, "../Agency/CompetePriceSwitch.aspx");
        Response.Write("<script>window.location=\"CompetePriceSwitch.aspx?Projectid=" + ComSwitchPrj.ToString() + "\"</script>");
    }
}
